/***************************************************************************
 * *   File name: ClassFactory.h
 * *    Describe: 实现类的注册
 * *  Created on: 2016-8-6
 * *      Author: dengxiudong
 * ************************************************************************/ 
#ifndef _CLASS_FACTORY_H_
#define _CLASS_FACTORY_H_

#include "Protocol.h"

#include <map>
#include <memory>

class ObjBase
{
public:
	ObjBase():m_cmd(0){}
	virtual uint16_t getCmd();
	virtual bool handle(std::shared_ptr<Msg> msg)=0;
protected:
	uint16_t m_cmd;
};

class ClassFactory
{
public:
	ClassFactory();
	virtual ~ClassFactory();

	static ObjBase *getObject(uint16_t cmd);

public:
	static void registerClass(ObjBase *obj);

private:
	static std::map<uint16_t, ObjBase*> m_objMap;
};


#define REGISTER_CLASS(className) ClassFactory::registerClass(new className)

//可以通过下面的宏定义实现直接在业务中调用下面宏实现业务类的注册
//#define REGISTER_CLASS(className) \
//class className##Register \
//{ \
//public: \
//	className##Register() \
//	{ \
//		ClassFactory::registerClass(new className); \
//	} \
//}; \
//const className##Register reg##className



#endif

